/*@Copyright (c) 2025 stray
*@author:	stray
*@date	:	2025-04-21
*@usage	:	升降机上位机
********************************************************************/
#ifndef LIFT_UPPER_H
#define LIFT_UPPER_H

#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>
#include <QTimer>
#include <QDateTime>


enum BIND_STATUS{
    NO_BIND=0,
    WAITTING_CONNECT,
    CONNECTED
};

enum LIFT_BEHAVIOR{
    LIFT_STOP=0,
    LIFT_RUN
};

enum LIFT_ERROR{
    NORMAL=0,
    OVER_SPEED,//过速检测
    ERROR_MOVE,//定点限速检测
    ERROR_DIRCTION,//错向检测
    ERROR_STOP,//失速检测
};

#pragma pack(1)
struct LIFT_STATUS{
    float height;
    int32_t behavior;
    int32_t error_type;
};
#pragma pack()
#pragma pack(1)
struct LIFT_CONTROL{
    int32_t displacement;
    int32_t speed;
};
#pragma pack()



QT_BEGIN_NAMESPACE
namespace Ui {
class lift_upper;
}
QT_END_NAMESPACE

class lift_upper : public QWidget
{
    Q_OBJECT

public:
    lift_upper(QWidget *parent = nullptr);
    ~lift_upper();

public slots:
    void buttom_bind_slot();//连接按键槽函数
    void readData();//读数据
    void pushButtom_start_slot();//启动槽函数
    void pushButtom_stop_slot();//停止槽函数

private:
    Ui::lift_upper *ui;
    LIFT_STATUS lift_status;
    LIFT_CONTROL lift_control;
    qint64 last_receive_time;
    QTcpSocket *localSocket;
    QTimer *tcpSenderTimer;
    QTimer *heartbeatTimer;
    void connectToHost();
};
#endif // LIFT_UPPER_H
